package cate.common.table.pvp.minecraft.mine_area_base;

import cate.common.table.EExcelNoteField;
import cate.common.table.EExcelRowClass;
import cate.common.table.ERow;
import cate.common.table.d.GDPosition;
import cate.common.util.SplitParser;
import cate.common.util.random.RandomDropItem;
import easy.java.dev.note.NoteField;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

@EExcelRowClass(note = "灵能矿洞-灵能矿洞跨服 Row", IDTitle = "主键id")
public class MinecraftMineAreaBaseRow extends ERow {
    @EExcelNoteField(fieldName = "矿洞层数id")
    public int layer;
    @EExcelNoteField(fieldName = "挖矿时长")
    public int hangMaxMinutes;
    @EExcelNoteField(fieldName = "防守怪物实例")
    public String insCode;
    @EExcelNoteField(fieldName = "防守怪物二队实例")
    public String insCode2;
    @EExcelNoteField(fieldName = "占领奖励")
    public String monsterRewardStr;
    @EExcelNoteField(fieldName = "每分钟资源产出")
    public String hangResPerMinuteStr;
    @EExcelNoteField(fieldName = "挂机掉落")
    public String randomDropStr;

    @NoteField("随机掉落列表")
    public List<RandomDropItem> randomDropList = new ArrayList<>();

    @Override
    public void decode() {
        super.decode();
        randomDropList.clear();
        randomDropList = SplitParser.parse(RandomDropItem.class, randomDropStr);
        randomDropList.removeIf(item -> item.weight <= 0);
    }

    /**
     * 根据分组获取怪物实例
     *
     * @param posNum 分组位置
     */
    public String getInsCode(byte posNum) {
        switch (posNum) {
            case GDPosition.POS_ONE:
                return insCode;
            case GDPosition.POS_TWO:
                return insCode2;
            default:
                return null;
        }
    }

    /**
     * 获取怪物分组数量
     */
    public int getPosNum(){
        int num = 0;
        if(StringUtils.isNotBlank(insCode)){
            num++;
        }
        if(StringUtils.isNotBlank(insCode2)){
            num++;
        }
        return num;
    }
}
